@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = "_Layout";
}
<body class="layui-anim layui-anim-up">

    <form class="layui-form">
			
			<div class="layui-upload">
					<label class="layui-form-label">请上传文件</label>
					<input type="hidden" name="url" lay-verify="required" id="FilUrl" value="" />
					<button type="button" class="layui-btn" id="test1">上传</button>
					<div class="layui-input-block">
							<p id="demoText"></p>
					</div>
			</div>
		

        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <input type="hidden" name="workId" value="@ViewContext.HttpContext.Request.Query["workId"]" />
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input type="text" name="sort" lay-verify="required|number" placeholder="请输入序号" class="layui-input">
            </div>
        </div>

        <!--<div class="layui-form-item layui-form-text">
      <label class="layui-form-label">编辑器</label>
      <div class="layui-input-block">
        <textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
      </div>
    </div>-->
        <div class="layui-form-item" align="center">
            <button class="layui-btn layui-btn-normal btnEdit" lay-submit="" lay-filter="btnEdit" style="display:none;">操作</button>
        </div>
    </form>

    <script>
        layui.use(['form','layer','upload'], function(){
        $=layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        var upload=layui.upload;



        //普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '/Admin/Banner/UploadFilesAjax'
		,accept: 'file'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){

$('#demoText').html('<span style="color: #FF5722;">正在上传</span>')

      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        layer.msg('上传失败');
      }else{
				$("#FilUrl").val(res.data.src);
       layer.msg('上传成功');
			 $('#demoText').html('<span style="color: #FF5722;">已成功上传</span>');
			 $("#test1").text("重新上传");
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });


                  //监听提交
			form.on('submit(btnEdit)', function(data){

				var obj = data.field;
				if (obj.State="on") {
					obj.State = true;
				}
				HsCms.AjaxJson("/Admin/Chapter/Add", "post", obj, function (result) {
				  if (result.state === "OK") {
					  HsCms.CloseFrame();
					  HsCms.ParentLoad("chapter");
				  }
				  HsCms.ParentMsg(result.msg);
			  });



            @*//发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });*@
            return false;
          });



       });
    </script>

</body>